home *** CD-ROM | disk | FTP | other *** search
/ hornet.scene.org / hornet.scene.org FTP 11-25-2012.zip / hornet.scene.org FTP 11-25-2012 / code / effects / bump / bump.doc < prev    next >
Text File  |  2012-06-16  |  4KB  |  91 lines

  1.  
  2.                          
  3.                A Fast Approach at Real-Time Phong Bump Mapping
  4.                                    (maybe)
  5.                               by Frenzy / TeSkO
  6.  ────────────────────────────────────────────────────────────────────────────
  7.  This is an idea about how to do real-time phong bump mapping. I'm not sure
  8.  if it will work or if there are any shortfalls in this approach. Please do
  9.  not flame me if this sounds absolutly wrong. It was an idea and I have yet
  10.  to implement it. I just thought I'd write it down for people to read and
  11.  maybe add some CONSTRUCTIVE advice. Of course, if you've done bump mapping
  12.  and you know that this is not the way to do it then please tell me :)
  13.  Don't tell me the slow interpolating normals method. Thats not any good
  14.  for real time! Whatever your thoughts, at least it might make you think or
  15.  at least come up with an idea of your own..
  16.  
  17.  
  18.  The Idea:
  19.  ────────────────────────────────────────────────────────────────────────────
  20.  You firstly have two maps. One is the texture map and the other is a bump
  21.  map. They are identical except the bump map is precalculated and does
  22.  not represent pixel colour like the texture map. If you were to draw them
  23.  both on screen you'd see they look like each other but the bump map would
  24.  have weird colours :)
  25.  
  26.  First thing you should do is calculate the theta values for each vertex
  27.  in the polygon. Just like in angular interpolated phong. You take the
  28.  dot product of the light vector with your vertex normals.
  29.  
  30.  cos THETA = Lx*Nx + Ly*Ny + Lz*Nz
  31.  THETA = ARCCOS(cos(THETA))
  32.  
  33.  Now its time to texture map. I'm assuming a linear distortional texture
  34.  mapping approach. I don't think perspective corrected texture mapping is a
  35.  good idea for this :) Interpolate your U,V coordinates like you would
  36.  normally but also interpolate those theta values like you would in
  37.  phong. Now, your ready to draw a scan line. You have, or at least should
  38.  have two things.. A set of U,V coordinates to index into the texture map
  39.  and a THETA value. This is where we start the bump mapping..
  40.  
  41.  Pull out a pixel from the texture map using the U,V coordinates. Call this
  42.  pixel colour 'C'.
  43.  
  44.  Next pull out a byte (not a pixel colour) from the bump map using the
  45.  same U,V coordinates. Call this value 'D'.
  46.  
  47.  Now, the bytes in the bump map should be of signed magnitude.
  48.  
  49.  We now add the D value to your THETA value. This displaces the theta value
  50.  by a small amount. Now, we compute the shade/intensity of that colour 'C'.
  51.  
  52.  We use a lookup table structured like this:-
  53.  
  54.                      IntensityTable[colour][shade];
  55.          
  56.  colour is the colour of the pixel you are working on, in this case 'C'.
  57.  shade is the shade of the value we want for that colour.
  58.  
  59.  We also have some more work to do. We have to precalculate a table I'm
  60.  going to call this PhongIntensityTable. This will be calculated like
  61.  so:-
  62.  
  63.              PhongIntensityTable[0..256]=cos(THETA)*MAXSHADES;
  64.  
  65.  Still with me? Hope so..
  66.  
  67.  This is what we do.. Using our displaced THETA value we calculate the
  68.  colour to plot like this:-
  69.  
  70.   PixelColour = IntensityTable[C][PhongIntensityTable[THETA]]
  71.  
  72.  Then we plot PixelColour where we would of ploted the original value of
  73.  'C' if we were only texture mapping.
  74.  
  75.  Keep doing this until we have finished the scan line and move onto the
  76.  next. This might sound slow but its only using lookups. The only calc's
  77.  your doing is the interpolation which you would do anyway and that single
  78.  add in the loop.. All tables are pre-calculated.
  79.  
  80.  
  81.  Has this gave you any amazing idea's? Are you totally in agreement with
  82.  me? Are you completly bamboozled?? Whatever your thoughts please tell
  83.  me and let me share in your ideas too :)
  84.  
  85.  Byeeee
  86.  
  87.  Signed,
  88.  Paul aka Frenzy
  89.  EMAIL: p.adams@wlv.ac.uk
  90.  
  91.